package com.qq.clone.user.Controller;

import com.qq.clone.common.response.CommonResponse;
import com.qq.clone.user.Controller.VO.LoginRequestVO;
import com.qq.clone.user.Controller.VO.LoginResponseVO;
import com.qq.clone.user.Controller.VO.UserRegisterVO;
import com.qq.clone.user.Db.DO.UserDO;
import com.qq.clone.user.Service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/users")
@Tag(name = "用户模块",description = "用户相关接口")
@Lazy
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("/hello")
    @Operation(summary = "测试接口")
    public Mono<String> hello() {
        return Mono.just("Hello from User Service!");
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册", description = "注册新用户")
    public Mono<CommonResponse<UserDO>> register(@RequestBody UserRegisterVO user) {
        return userService.register(user).map(CommonResponse::success);
    }
    // TODO: 参考公司项目看一下如何输出接口调用位置

    @PostMapping("/login")
    @Operation(summary = "用户登录", description = "用户登录")
    public Mono<CommonResponse<LoginResponseVO>> login(@RequestBody LoginRequestVO loginRequest) {
        return userService.login(loginRequest).map(CommonResponse::success);
    }

    @GetMapping("/get-user-by-id")
    @Operation(summary = "通过ID获取用户信息", description = "获取指定ID的用户信息")
    public Mono<CommonResponse<UserDO>> getUserById(@RequestParam Long userId) {
        return userService.getUserById(userId).map(CommonResponse::success);
    }
}